Breakpoints in C#

The first thing about debugging, which you should know, is a breakpoint. It really is actually what the name means - this is a point in your code where execution will take a break (and no, it really does not take your code Will not break, do not worry). Keeping a breakpoint from Visual Studio or Express editions, left-click in the gutter, which is at the left of your code, is so easy. Once you click it, you will get a bright, red circle in the form of a reward - the marks of this cycle where you can stop the debugger while executing your application. You keep a better watch for yourself, and to see the effect, we will use the following code:


namespace DebugTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 5, b = 8, c = 233;
            int d = a + c - b;
            Console.WriteLine(d);
        }
    }
}

Now, can you guess the result by seeing the code? Perhaps, and if not, you can take the old calculator and make math, but in reality this is not the case. Just think that the amount of code is very high, and debug this thing! Click on the left gutter to capture the breakpoint - Your IDE should now look like this:

Breakpoint

Okay, you are ready to start your first debugging session. As soon as you put breakpoints, you can run your application normally - by pressing the toolbar or F5, from the menu. What happens now is that this application is executed normally, but after the line break with breakpoint, the execution of that line closes before the execution is closed. In this case, this means that the variable value of A, B and C will be, but D will have a default value (which is 0 for an integer) because it will not be set before the line with breakpoint evaluation, here The best part comes - Try moving your mouse over different variables - IDE will tell you what they include. As mentioned, its default value will be in D value, but let's move it to execution and replace it. In the next chapter, I'll show you how to navigate around your code, while it is being executed.